import requestApi from '../requestApi';
import presetVar from '../presetVar';
import {toast} from 'nc-lightapp-front';

export default function searchClick(props, searchVal, isDefaultSearch) {
    const multiLang = props.MutiInit.getIntl(2011);
    if(true){
        let data={
            querycondition:searchVal==null?{}:searchVal,
            pagecode: presetVar.pageCode.searchPage,
            pageInfo:{
                "pageIndex":-1,
                "pageSize":10,
                "totalPage":"0"
            },
            queryAreaCode:presetVar.areaCode.searchArea,  //查询区编码
            oid:'0001Z3100000000083QM',  //查询模板id，手工添加在界面模板json中，放在查询区，后期会修改,pub_area中查询areaid
            querytype:'tree',
            tradetype: props.getUrlParam("tradetype") || window.presetVar.tradetype
        };
        let senddata = {data,"pagecode":presetVar.pagecode2,"tepmid":this.props.meta.getMeta().pageid};
        requestApi.query({
            data:senddata,
            success: (data) => {
                let totalCount = 0;
                //是否是无金额申请
                const noAmount = props.search.getSearchValByField(presetVar.areaCode.searchArea, 'noamount')
                const isNoAmount = noAmount.value && noAmount.value.firstvalue
                //无金额 隐藏金额字段  orig_amount => head.items[] and mtapp_detail.items[]
                const metas = props.meta.getMeta()
                const filterKeys = ['rest_amount', 'orig_amount', 'pk_currtype']
                metas.head.items =  isNoAmount ? 
                                    metas.head.items.filter(item => { if(filterKeys.includes(item.attrcode)) {item.visible = false} return true}) 
                                    : 
                                    metas.head.items.filter(item => { if(filterKeys.includes(item.attrcode)) {item.visible = true} return true}) 
                metas.mtapp_detail.items =  isNoAmount ? 
                                            metas.mtapp_detail.items.filter(item => { if(filterKeys.includes(item.attrcode)) {item.visible = false} return true}) 
                                            : 
                                            metas.mtapp_detail.items.filter(item => { if(filterKeys.includes(item.attrcode)) {item.visible = true} return true}) 
                props.meta.setMeta(metas)
                
                if(data){
                    totalCount = data.length;
                    data && this.props.transferTable.setTransferTableValue(presetVar.areaCode.billsArea, presetVar.areaCode.bodysArea, data, 'pk_mtapp_bill', 'pk_mtapp_detail');
                }else{
                    this.props.transferTable.setTransferTableValue(presetVar.areaCode.billsArea, presetVar.areaCode.bodysArea, [], 'pk_mtapp_bill', 'pk_mtapp_detail');
                }
                
                isDefaultSearch != 'defaultSearch' && toast({
                    color: 'success',
                    title: multiLang && multiLang.get('201102BCLF-0055'),
                    content: (multiLang && multiLang.get('201102BCLF-0056') || '').replace('{count}', data && data.length || 0)
                })

            }
        })
    }
}

